class BlogsController < ApplicationController
	before_filter :login_required
	def new
	  @images=(params[:imgs].nil?)? []:params[:imgs].split("==");
	  @article = Article.new
	  @article.body = params[:body]||""
	  @article.person_id= current_person.id
  
	end
  
	def show
		@article = Article.find(params[:id])
		respond_to do |wants|
		  wants.html
		  wants.xml { render :xml => @article.to_xml }
		end		
	end
  
	def index
	end
  
	def create

		params[:article][:categoryt_id]=0 if params[:article][:categoryt_id].blank?
		params[:article][:tag_id]=0 if params[:article][:tag_id].blank?
		@article = Article.create(params[:article])

		event_manager=EventManager.new(@article.person_id)
		event_manager.post_article(@article)
		

		respond_to do |wants|
		  wants.html { redirect_to cat_blog_path(@cat_id,@article.id) }
		  wants.xml  { render :xml => @article.to_xml }
		end		
	end
  
	def update
		@article = Article.find(params[:id])
		@article.update_attributes(params[:article])
		respond_to do |wants|
		  wants.html { redirect_to cat_blog_path(@cat_id,@article.id) }
		  wants.xml  { render :xml => @article.to_xml }
		end	
	end
  
	def destroy
		@article = Article.find(params[:id])
		@article.destroy
		respond_to do |wants|
		  wants.html { redirect_to blogs_cat_person_path(@article.category_id,@article.person) }
		  wants.xml  { render :nothing => true }
		end		
	end
  
	def edit
		@article = Article.find(params[:id])
	end
end
